#    Stingingnettlepy - A website generator for creating simple static websites.
#    Copyright (C) 2013  Jannik Haberbosch
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.


# Standard Python modules.
import os
import os.path

# Project modules
from stingingnettlepy.constants import constants
from stingingnettlepy.classes.Template import Template


def load_templates():
	"""Creates 'Template' objects that represent templates and returns those
	as a list.
	
	Return values
		list()
			A list containg the 'Template' instances.

	"""
	templates = []
	for template_filename in os.listdir( constants.RELPATH_TEMPLATES ):
		templates.append(
			Template(
				os.path.join( constants.RELPATH_TEMPLATES, template_filename )
			)
		)
		
	return templates


def get_template( templates, template_name ):
	"""Returns a 'Template' instance of the 'templates' tuple whose 'name'
	property matches 'template_name'.
	
	If no suitable 'Template' instance has been found, 'None' is returned.
	
	"""
	for template in templates:
		if template.name == template_name:
			return template
			
	return None
